﻿<Page x:Class="DPChangedExtension.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="using:DPChangedExtension"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      mc:Ignorable="d">

    <Page.DataContext>
        <local:DemoVM />
    </Page.DataContext>
    <Page.Resources>
        <DataTemplate x:Key="DemoControlDataTemplate">
            <local:DemoControl DataContext="{Binding Path=DemoDataContext}"
                               Visibility="{Binding Path=DataContext.DemoVisibility, ElementName=MainContent}"
                               IsHitTestVisible="{Binding Path=DataContext.DemoIsHitTestVisible, ElementName=MainContent}" />
        </DataTemplate>

        <local:DemoDataContentTemplateSelector x:Key="TemplateSelector"
                                               DemoDataTemplate="{StaticResource DemoControlDataTemplate}" />
    </Page.Resources>
    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <StackPanel Orientation="Horizontal"
                    HorizontalAlignment="Center"
                    Margin="0,15,0,0">
            <Button Command="{Binding Path=InitializeDemoDataCommand}"
                    Content="Create Demo Control" />
            <Button Command="{Binding Path=RemoveDemoDataCommand}"
                    Content="Remove Demo Control" />

            <Button Command="{Binding Path=ChangeDemoDataContextCommand}"
                    Content="Change DataContext"
                    Margin="10,0,0,0" />
            <Button Command="{Binding Path=ChangeDemoVisibilityCommand}"
                    Content="Change Visibility" />
            <Button Command="{Binding Path=ChangeDemoIsHitTestVisibleCommand}"
                    Content="Change IsHitTestVisible" />
        </StackPanel>
        <ContentControl x:Name="MainContent"
                        Content="{Binding Path=DemoDataContent}"
                        ContentTemplateSelector="{StaticResource TemplateSelector}"
                        Grid.Row="1"
                        HorizontalContentAlignment="Center"
                        VerticalContentAlignment="Center">
        </ContentControl>
    </Grid>
</Page>
